cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        _jushuxuanze:null,
        _leixingxuanze:null,
        _dingzhuan:null
    },

    // use this for initialization
    onLoad: function () {
        this._leixingxuanze = [];
        var leixing = this.node.getChildByName("leixingxuanze");
        for(var i = 0; i < leixing.childrenCount; ++i){
            var n = leixing.children[i].getComponent("RadioButton");
            if(n != null){
                this._leixingxuanze.push(n)
            }
        };
        var paijiuNode=leixing.children[0].getChildByName("contNode");
        this._jushuxuanze = [];
        var t = paijiuNode.getChildByName("xuanzejushu");
        for(var i = 0; i < t.childrenCount; ++i){
            var n = t.children[i].getComponent("RadioButton");
            if(n != null){
                this._jushuxuanze.push(n)
            }
        };
        this._dingzhuan = [];
        var t = paijiuNode.getChildByName("dingzhuang");
        for(var i = 0; i < t.childrenCount; ++i){
            var n = t.children[i].getComponent("RadioButton");
            if(n != null){
                this._dingzhuan.push(n)
            }
        }
    },

    onBtnBack:function(){
        this.node.active = false
    },
    
    onBtnOK:function(){
        this.node.active = false;
        this.createRoom()
    },
    
    createRoom:function(){
        var self = this;
        var onCreate = function(ret){
            if(ret.errcode !== 0){
                cc.vv.wc.hide();
                if(ret.errcode == 2222){
                    cc.vv.alert.show("提示","房卡不足，创建房间失败!")
                }else{
                    cc.vv.alert.show("提示","创建房间失败："+ret.errmsg+"\n错误码:" + ret.errcode)
                }
            }else{
                cc.vv.gameNetMgr.connectGameServer(ret)
            }
        };
        var failFn = function(){
            console.log("failFn");
            if (cc.vv.wc.node) {
                cc.vv.wc.hide()
            }
        };
        var gpsArr = [-1,-1];
        if(cc.vv.anysdkMgr.getGPSLocation()){
            var gps = cc.vv.anysdkMgr.getGPSLocation();
            gpsArr = gps.split("_");
            console.log("经纬度",gpsArr)
        };
        
        var type = 0;
        for(var i = 0; i < self._leixingxuanze.length; ++i){
            if(self._leixingxuanze[i].checked){
                type = i+10;
                break
            }     
        };
        if (type==10) {
            var maxGames = 0;
            for(var i = 0; i < self._jushuxuanze.length; ++i){
                if(self._jushuxuanze[i].checked){
                    maxGames = i;
                    break
                }     
            };
            var bankertype = 0;
            for(var i = 0; i < self._dingzhuan.length; ++i){
                if(self._dingzhuan[i].checked){
                    bankertype = i;
                    break
                }     
            };
            var conf = {
                type:10,
                jushuxuanze:maxGames,
                bankertype:bankertype
            }
        };
        // 区分是俱乐部房间还是普通房间
        if (cc.vv.userMgr.isCreate) {
            var data = {
                clubid:cc.vv.club.nowClubData.clubid,
                account:cc.vv.userMgr.account,
                sign:cc.vv.userMgr.sign,
                conf:JSON.stringify(conf),
                lat:gpsArr[0],
                lng:gpsArr[1]
            }
        }else{
            var data = {
                account:cc.vv.userMgr.account,
                sign:cc.vv.userMgr.sign,
                conf:JSON.stringify(conf),
                lat:gpsArr[0],
                lng:gpsArr[1]
            }
        };
        console.log("创建房间data",data);
        cc.vv.wc.show("正在创建房间");
        cc.vv.http.sendRequest("/create_private_room",data,onCreate,null,failFn,this)
    }

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
